package com.eway.viewanimator;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

public class AnimateLayoutChangesActivity extends AppCompatActivity implements View.OnClickListener {

	private Button add, delte;
	private LinearLayout containCollector;
	private int i = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_animate_layout_changes);


		add = (Button) findViewById(R.id.add);
		delte = (Button) findViewById(R.id.delte);
		containCollector = (LinearLayout) findViewById(R.id.contain_collector);

		add.setOnClickListener(this);
		delte.setOnClickListener(this);


	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
			case R.id.add:
				i++;
				LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
				Button button = new Button(AnimateLayoutChangesActivity.this);
				button.setText("btn" + i);
				button.setLayoutParams(params);
				containCollector.addView(button);
				break;

			case R.id.delte:
				if (i > 0) {
					containCollector.removeViewAt(0);
				}

				break;
			default:
				break;
		}
	}
}
